import { getAction, deleteAction, putAction, postAction, httpAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from "@/store/mutation-types"

// 增加接口
// 1 核算单元查询
const getUintList = (params) => getAction("unit/gmAccountingUnit/unitList", params);
// 2 根据行业指南获取核算标准
const getAccountingStandardsByUint = (params) => getAction("/standard/accountingStandard/queryListByIndustry", params);
// 3 获取填报数据初始化版本1
const getInitAddUnitByUnitId = (params) => getAction("/accounting/gmAccountingFilling/initFillingData", params);
// 3 获取填报数据初始化版本2
const getInitUnitDataByUnitId = (params) => getAction("/accounting/gmAccountingFilling/prepareFillingData", params);

// 添加核算排放报告
const accountingFill = (params) => postAction("/accounting/gmAccountingFilling/add", params);
// 核算任务-1企业信息
const accountingFillBaseInfo = (params) => postAction("/accounting/gmAccountingBasicInfo/saveOrUpdate", params);
// 测试接口
const getGmAccountingBasicInfoListTest = (params) => getAction("/accounting/gmAccountingBasicInfo/list", params);

// 数据审核查看基本信息
const auditInformant = (params) => getAction("/accounting/audit/informant", params);

// 首页 
// 碳交易信息
const getCarbonTransaction = (params) => getAction("/index/transaction", params);
// 排放量
const getCarbonEmissions = (params) => getAction("/index/emissions", params);
// 排放设施消耗量排名
const getFacilityRanking = (params) => getAction("/index/facilities", params);
// 碳价格趋势
const getPricesTrend = (params) => getAction("/index/prices", params);
// 待办任务项
const getUpComing = (params) => getAction("/index/upcoming", params);


//角色管理
const addRole = (params) => postAction("/sys/role/add", params);
const editRole = (params) => putAction("/sys/role/edit", params);
const checkRoleCode = (params) => getAction("/sys/role/checkRoleCode", params);
const queryall = (params) => getAction("/sys/role/queryall", params);

//用户管理
const addUser = (params) => postAction("/sys/user/add", params);
const editUser = (params) => putAction("/sys/user/edit", params);
const queryUserRole = (params) => getAction("/sys/user/queryUserRole", params);
const getUserList = (params) => getAction("/sys/user/list", params);
const frozenBatch = (params) => putAction("/sys/user/frozenBatch", params);

//设施管理
const addEquipment = (params) => postAction('/accounting/gmAccountingFacilitiesInfo/add', params)
const editEquipment = (params) => putAction('/accounting/gmAccountingFacilitiesInfo/edit', params)
const getFacilitiesList = (params) => getAction('/accounting/gmAccountingFacilitiesInfo/list', params)
// 设施绑定边界
const saveFacilitiesBoundary = (params) => putAction('/accounting/facilitiesBoundary/saveFacilitiesBoundary', params)
const getBindingBoundary = (params) => getAction('/accounting/facilitiesBoundary/queryBindingBoundary', params)
const relieveBindingBoundary = (params) => deleteAction('/accounting/facilitiesBoundary/removeBindingBoundary', params)
// 核算任务
// 任务绑定设施
// const queryFacilitiesBoundaryPageList = (params) => getAction('/accounting/facilitiesBoundary/queryFacilitiesBoundaryPageList', params)
const queryFacilitiesBoundaryPageList = (params) => getAction('/accounting/facilitiesBoundary/queryList', params)
const saveTaskBoundary = (params) => postAction('/accounting/boundaryTask/saveTaskBoundary', params)
const taskList = (params) => getAction('/accounting/task/list', params)




// 任务状态
const updateTaskStatus = (params) => postAction('/accounting/task/updateTaskStatus', params)
// 根据任务编号查询设施排放源
const queryTaskBoundaryList = (params) => getAction('/accounting/boundaryTask/queryTaskBoundaryList', params)
const queryView = (params) => getAction('/accounting/boundaryTask/view', params)
// 核算任务-核算汇总任务查询
const querySummaryView = (params) => getAction('/accounting/summary/view', params)

// 排放边界管理
const getAccountingBoundary = (params) => getAction('/accounting/gmAccountingBoundary/queryTreeListByIndustryId', params)
//指定行业 边界查询
const queryBindingBoundaryByIndustry = (params) => getAction('/accounting/facilitiesBoundary/queryBindingBoundaryByIndustry', params)
const getAccountingItem = (params) => getAction('/accounting/gmAccountingItem/queryListByBoundaryId', params)
const editIndustry = (params) => putAction('/accounting/gmAccountingIndustry/edit', params)
const addIndustry = (params) => postAction('/accounting/gmAccountingIndustry/add', params)

// 行业管理
const getAccountingIndustry = (params) => getAction('/accounting/gmAccountingIndustry/queryList', params)
// 用户切换任务列表
const queryTasktListBuUserId = (params) => getAction('/accounting/task/queryTaskListByUserId', params)
//根据任务ID获取填报任务
const queryTaskBoundaryListByTaskId = (params) => getAction('/accounting/boundaryTask/queryTaskBoundaryListByTaskId', params)
//获取任务填报信息
const queryFillingParamInfo = (params) => getAction('/accounting/boundaryTask/queryFillingParamInfo', params)
// 填报核算项
const updateTaskBoundary = (params) => postAction('/accounting/boundaryTask/updateTaskBoundary', params)
// 核算任务- 根据填报编号查看排放源填报信息
const queryFillingTask = (params) => getAction('/accounting/boundaryTask/queryFillingTask', params)
//验证用户是否存在
const checkOnlyUser = (params) => getAction("/sys/user/checkOnlyUser", params);
//改变密码
const changePassword = (params) => putAction("/sys/user/changePassword", params);

// 部门核算审核
const queryDepartAuditList = (params) => getAction("/accounting/audit/list", params);
// 任务审核

// 任务排放源审核
const emissionSourceAudit = (params) => getAction("/accounting/audit/approve", params);
// 批量操作审核
const batchEmissionSourceAudit = (params) => getAction("/accounting/audit/approve/list", params);
// 催填
const urge = (params) => postAction("/accounting/audit/urge", params);

// 核算报告模块  
// 新建报告-获取已审核核算任务列表-关联任务
const queryFinishedTaskList = (params) => getAction("/accounting/report/queryFinishedTaskList", params);
// 报告审核添加
const addReoprt = (params) => postAction("/accounting/report/generateReport", params);
// 生成报告键和值的对应关系
// 根据行业编号生成排放源属性值
const generateKey = (params) => getAction("/accounting/report/generateKey", params);
// 生成报告，根据键取值
const generateReport = (params) => getAction("/accounting/report/generateReport", params);
// 预览报告
 const reportPreview = (params) => getAction("/accounting/report/preview", params);
// 已审核



//权限管理
const addPermission = (params) => postAction("/sys/permission/add", params);
const editPermission = (params) => putAction("/sys/permission/edit", params);
const getPermissionList = (params) => getAction("/sys/permission/list", params);
const getSystemMenuList = (params) => getAction("/sys/permission/getSystemMenuList", params);
const getSystemSubmenu = (params) => getAction("/sys/permission/getSystemSubmenu", params);
const getSystemSubmenuBatch = (params) => getAction('/sys/permission/getSystemSubmenuBatch', params)
const queryTreeList = (params) => getAction("/sys/permission/queryTreeList", params);
const queryTreeListForRole = (params) => getAction("/sys/role/queryTreeList", params);
const queryListAsync = (params) => getAction("/sys/permission/queryListAsync", params);
const queryRolePermission = (params) => getAction("/sys/permission/queryRolePermission", params);
const saveRolePermission = (params) => postAction("/sys/permission/saveRolePermission", params);
const queryPermissionsByUser = () => getAction("/sys/permission/getUserPermissionByToken");
const loadAllRoleIds = (params) => getAction("/sys/permission/loadAllRoleIds", params);
const getPermissionRuleList = (params) => getAction("/sys/permission/getPermRuleListByPermId", params);
const queryPermissionRule = (params) => getAction("/sys/permission/queryPermissionRule", params);

// 部门管理
const queryDepartTreeList = (params) => getAction("/sys/sysDepart/queryTreeList", params);
const queryDepartTreeSync = (params) => getAction("/sys/sysDepart/queryDepartTreeSync", params);
const queryIdTree = (params) => getAction("/sys/sysDepart/queryIdTree", params);
const queryParentName = (params) => getAction("/sys/sysDepart/queryParentName", params);
const searchByKeywords = (params) => getAction("/sys/sysDepart/searchBy", params);
const deleteByDepartId = (params) => deleteAction("/sys/sysDepart/delete", params);

//二级部门管理
const queryDepartPermission = (params) => getAction("/sys/permission/queryDepartPermission", params);
const saveDepartPermission = (params) => postAction("/sys/permission/saveDepartPermission", params);
const queryTreeListForDeptRole = (params) => getAction("/sys/sysDepartPermission/queryTreeListForDeptRole", params);
const queryDeptRolePermission = (params) => getAction("/sys/sysDepartPermission/queryDeptRolePermission", params);
const saveDeptRolePermission = (params) => postAction("/sys/sysDepartPermission/saveDeptRolePermission", params);
const queryMyDepartTreeList = (params) => getAction("/sys/sysDepart/queryMyDeptTreeList", params);

//日志管理
const deleteLog = (params) => deleteAction("/sys/log/delete", params);
const deleteLogList = (params) => deleteAction("/sys/log/deleteBatch", params);

//数据字典
const addDict = (params) => postAction("/sys/dict/add", params);
const editDict = (params) => putAction("/sys/dict/edit", params);
const treeList = (params) => getAction("/sys/dict/treeList", params);
const addDictItem = (params) => postAction("/sys/dictItem/add", params);
const editDictItem = (params) => putAction("/sys/dictItem/edit", params);

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/sys/dict/getDictItems/${code}`, params);
//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  //   console.log(Vue.ls.get(UI_CACHE_DB_DICT_DATA))
  if (Vue.ls.get(UI_CACHE_DB_DICT_DATA) && Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode]) {
    let dictItems = Vue.ls.get(UI_CACHE_DB_DICT_DATA)[dictCode];
    return dictItems;
  }
}

//系统通告
const doReleaseMessage = (params) => getAction("/accounting/task/attention/list", params);
// 收藏阅读数据
const MessageFavorite = (params) => getAction("/accounting/task/attention/favorite", params);
// 更改阅读数据的状态
const MessageReadStatus = (params) => getAction("/accounting/task/attention/read", params);
const doReleaseData = (params) => getAction("/sys/annountCement/doReleaseData", params);
const doReovkeData = (params) => getAction("/sys/annountCement/doReovkeData", params);
//获取系统访问量
const getLoginfo = (params) => getAction("/sys/loginfo", params);
const getVisitInfo = (params) => getAction("/sys/visitInfo", params);

// 根据部门主键查询用户信息
const queryUserByDepId = (params) => getAction("/sys/user/queryUserByDepId", params);
// 通过用户id查部门
const queryUserDepartList = (params) => getAction("/sys/user/userDepartList", params);

// 重复校验
const duplicateCheck = (params) => getAction("/sys/duplicate/check", params);
// 加载分类字典
const loadCategoryData = (params) => getAction("/sys/category/loadAllData", params);
const checkRuleByCode = (params) => getAction('/sys/checkRule/checkByCode', params)
//加载我的通告信息
const getUserNoticeInfo = (params) => getAction("/sys/sysAnnouncementSend/getMyAnnouncementSend", params);
//查询图表数据
const getTransitURL = url => `/sys/common/transitRESTful?url=${encodeURIComponent(url)}`
// 中转HTTP请求
export const transitRESTful = {
  get: (url, parameter) => getAction(getTransitURL(url), parameter),
  post: (url, parameter) => postAction(getTransitURL(url), parameter),
  put: (url, parameter) => putAction(getTransitURL(url), parameter),
  http: (url, parameter) => httpAction(getTransitURL(url), parameter),
}


const sendMessage = (params) => postAction("/sys/socketTest/sendUser", params);


export {
  getUintList,
  getAccountingStandardsByUint,
  getInitAddUnitByUnitId,
  getInitUnitDataByUnitId,
  accountingFill,
  accountingFillBaseInfo,


  getGmAccountingBasicInfoListTest,

  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  queryDepartTreeList,
  queryDepartTreeSync,
  queryIdTree,
  queryParentName,
  searchByKeywords,
  deleteByDepartId,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  doReleaseData,
  doReovkeData,
  getLoginfo,
  getVisitInfo,
  queryUserByDepId,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  loadCategoryData,
  checkRuleByCode,
  queryDepartPermission,
  saveDepartPermission,
  queryTreeListForDeptRole,
  queryDeptRolePermission,
  saveDeptRolePermission,
  queryMyDepartTreeList,
  getUserNoticeInfo,
  getDictItemsFromCache,
  addEquipment,//添加设备
  editEquipment,//编辑设备
  getAccountingBoundary,//核算边界
  getAccountingItem,//核算条目
  addIndustry,
  editIndustry,
  getAccountingIndustry,//行业
  saveFacilitiesBoundary,
  getBindingBoundary,
  relieveBindingBoundary,
  queryBindingBoundaryByIndustry,
  getFacilitiesList,
  saveTaskBoundary,
  queryFacilitiesBoundaryPageList,
  taskList,
  queryTaskBoundaryList,
  queryView,
  updateTaskStatus,
  queryTasktListBuUserId,
  queryTaskBoundaryListByTaskId,
  queryFillingParamInfo,
  updateTaskBoundary,
  doReleaseMessage,
  MessageFavorite,
  MessageReadStatus,
  queryUserDepartList,
  queryDepartAuditList,
  emissionSourceAudit,
  batchEmissionSourceAudit,
  urge,
  queryFillingTask,
  queryFinishedTaskList,
  addReoprt,
  generateKey,
  generateReport,
  sendMessage,
  getCarbonTransaction,
  getCarbonEmissions,
  getFacilityRanking,
  getPricesTrend,
  getUpComing,
  auditInformant,
  querySummaryView,
  reportPreview
}



